<!DOCTYPE html>
<html>
<head>
    @include('layouts.admin.header')
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="wxSetForm" method="post" action="{{url('admin/permissionAdd')}}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限名称：</label>
                            <div class="col-sm-2">
                                <input name="display_name" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">父级权限：</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="pid">
                                    <option value="0">顶级权限</option>
                                    @foreach($list as $item)
                                        <option value="{{$item['id']}}">--{{$item['display_name']}}</option>
                                            @if(!empty($item['_child']))
                                                    @foreach($item['_child'] as $item1)
                                                        <option value="{{$item1['id']}}">----{{$item1['display_name']}}</option>
                                                    @endforeach
                                            @endif
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">路由：</label>
                            <div class="col-sm-2">
                                <input name="name" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">控制器：</label>
                            <div class="col-sm-2">
                                <input name="controller" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">方法：</label>
                            <div class="col-sm-2">
                                <input name="method" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图标：</label>
                            <div class="col-sm-2">
                                <input name="icon" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">method：</label>
                            <div class="col-sm-2">
                                <select class="form-control" name="type">
                                    <option value="1">any</option>
                                    <option value="2">get</option>
                                    <option value="3">post</option>
                                    <option value="4">put</option>
                                    <option value="5">delete</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">权限描述：</label>
                            <div class="col-sm-2">
                                <input name="description" class="form-control" type="text">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary submit_form" type="submit">提交</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <script src="/js/plugins/validate/jquery.validate.min.js"></script>
    <script>
        $.validator.setDefaults({
            highlight: function(e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            },
            success: function(e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            },
            errorElement: "span",
            errorPlacement: function(e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            },
            submitHandler: function() {
                $("#wxSetForm").ajaxSubmit({
                    dataType : "json",
                    success : ajaxCallback
                });

            },
            errorClass: "help-block m-b-none",
            validClass: "help-block m-b-none"
        });
        $().ready(function() {
            var e = "<i class='fa fa-times-circle'></i>";
            $("#wxSetForm").validate({
                rules: {
                    display_name: "required",
                    name: "required",
                    controller: "required",
                    method: "required"
                },
                messages: {
                    display_name: e + "请输权限名称",
                    name: e + "请输权限路由",
                    controller: e + "请输入控制器名称",
                    method: e + "请输入方法名"
                }
            })
        });
    </script>
</div>
</body>
</html>
